# 闭包实现模拟ATM取款机功能

def create_account(balance = 0):

    def atm(money, isSave = True):
        nonlocal balance
        if isSave:
            balance += money
            print(f"存款{money}, 余额{balance}")
        else:
            if money > balance:
                print("余额不足")
            else:
                balance -= money
                print(f"取款{money}, 余额{balance}")
    return atm

# 测试
account = create_account()
account(500)
account(2000, False)